
package it.csttech.date;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.validation.Valid;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

/**
 * OVERVIEW This class is a resource used to test float conversion according to
 * the locale
 * 
 * @author marcello.felappi
 * @author marco.dalena
 */
@Path("float")
public class FloatResource {

	@GET
	@Consumes(MediaType.APPLICATION_JSON)
	public Response postFloat(@QueryParam("number") Float fl) {

		return Response.ok().build();

	}

	@POST
	@Consumes(MediaType.APPLICATION_JSON)
	@Path("list")
	public Response postFloatList(List<Float> list) {

		for (Float f : list) {
			System.out.println(f);
		}
		return Response.ok().build();

	}

	@Produces(MediaType.APPLICATION_JSON)
	@GET
	@Path("list")
	public List<Float> getFloat() {

		List<Float> list = new ArrayList<Float>();
		list.add(812346.23f);
		list.add(892816.78f);

		return list;
	}

	@Path("complex")
	@GET
	@Produces(MediaType.APPLICATION_JSON)
	//@JsonProperty(value = "ComplexObject")
	public ComplexObject getComplex() {

		Map<String, Float> map = new HashMap<String, Float>();
		map.put("id", 12.3f);
		Date date = new Date();
		Float fl = 123.3f;
		List<Float> list = new ArrayList<Float>();
		list.add(12.34f);
		list.add(124.23f);
		return new ComplexObject(date, fl, map, list);

	}
	
	@Path("complexTwoList")
	@GET
	@Produces(MediaType.APPLICATION_JSON)
	public ComplexObjectTwoList getComplexTwoList() {

		Map<String, Float> map = new HashMap<String, Float>();
		map.put("id", 12.3f);
		Date date = new Date();
		Float fl = 123.3f;
		List<Float> list = new ArrayList<Float>();
		list.add(12.34f);
		list.add(124.23f);
		return new ComplexObjectTwoList(date, fl, map, list, list);

	}

	@Path("complex")
	@POST
	@Produces(MediaType.APPLICATION_JSON)
	public Response postComplex(ComplexObject obj) {

		Map<String, Float> map = obj.getMap();
		for (String s : map.keySet()) {
			Float f = map.get(s);
			System.out.println(s + f);

		}

		return Response.ok(obj).build();

	}

	@Path("listlist")
	@GET
	@Produces(MediaType.APPLICATION_JSON)
	public List<List<List<Float>>> getListList() {

		List<List<List<Float>>> superlist = new ArrayList<List<List<Float>>>();

		List<List<Float>> list = new ArrayList<List<Float>>();
		List<Float> listAdd1 = new ArrayList<Float>();
		listAdd1.add(123.234f);
		listAdd1.add(13.24f);
		listAdd1.add(12.23f);
		list.add(listAdd1);
		superlist.add(list);
		return superlist;

	}

	@Path("listlist")
	@Produces(MediaType.APPLICATION_JSON)
	@POST
	public Response postListList(ArrayList<List<List<Float>>> list) {

		return Response.ok(list).build();

	}

	@Path("complexList")
	@Produces(MediaType.APPLICATION_JSON)
	@GET
	public ListComplexObject getComplexList() {

		List<ComplexObject> complexList = new ArrayList<ComplexObject>();
		Map<String, Float> map = new HashMap<String, Float>();
		map.put("id", 12.3f);
		Date date = new Date();
		Float fl = 123.3f;
		List<Float> list = new ArrayList<Float>();
		list.add(12.34f);
		list.add(124.23f);
		ComplexObject twoMap =
			new ComplexObjectTwoMap(date, fl, map, list, map);
		ComplexObject twoList =
			new ComplexObjectTwoList(date, fl, map, list, list);
		complexList.add(twoMap);
		complexList.add(twoList);
		return new ListComplexObject(complexList);

	}
	@Path("complexList")
	@Produces(MediaType.APPLICATION_JSON)
	@POST
	public ListComplexObject postComplexList(@Valid ListComplexObject complex) {
		
		return complex;
		
	}
}
